package controller;


import utils.NoLoginUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;


@WebServlet(name = "LogoutServlet", value = "/logout")
public class LogoutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        NoLoginUtil.doVerify(request);
        HttpSession session = request.getSession();
        session.invalidate();
        for (Cookie cookie : request.getCookies()) {
            if ("core-data".equals(cookie.getName())) {
                Cookie c = new Cookie("core-data", "");
                c.setMaxAge(0);
                response.addCookie(c);
            }
        }
        response.sendRedirect("/");
    }
}
